package com.itheima.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.dao.FileDetailsDao;
import com.itheima.po.FileDetails;
import com.itheima.service.FileDetailsService;
@Service("fileDetailsService")
@Transactional
public class FileDetailsServiceImpl implements FileDetailsService {
	@Autowired
	private FileDetailsDao fileDetailsDao;

	@Override
	public List<FileDetails> showAllFile() {
		// TODO Auto-generated method stub
		return fileDetailsDao.findAllFile();
	}

	@Override
	public int insertFile(FileDetails fileDetails) {
		// TODO Auto-generated method stub
		return fileDetailsDao.insertFile(fileDetails);
	}

	@Override
	public String getFileName(String originalFilename, String name,String type) {
		// TODO Auto-generated method stub
		int dot = originalFilename.lastIndexOf(".");
		String prefix = originalFilename.substring(0, dot);
		String suffix = originalFilename.substring(dot + 1, originalFilename.length());
		System.out.println("prefix:" + prefix);
		System.out.println("suffix:" + suffix);
		String newFilename = prefix + "-"+type+ "-" + name + "." + suffix;
		System.out.println(newFilename);
		return newFilename;
	}

}
